//
//  YDADayNewsCell.m
//  siyanone
//
//  Created by LK-IOS on 2018/3/23.
//  Copyright © 2018年 LK-News. All rights reserved.
//

#import "YDADayNewsCell.h"
#import "YDADayNewsModel.h"



@interface YDADayNewsCell()


/**
 time icon
 */
@property (nonatomic, strong)UIImageView *icon;

/**
 时间
 */
@property (nonatomic, strong)UILabel *timeLbl;

/**
 白色背景
 */
@property (nonatomic, strong)UIView *bgView;

/**
 文本
 */
@property (nonatomic, strong)UILabel *titleLbl;




/**
 左边的虚线
 */
@property (nonatomic, strong)UILabel *leftLine;

@property (nonatomic,strong) CAShapeLayer *lineLayer;


@end

@implementation YDADayNewsCell


-(void)setModel:(YDADayNewsModel *)model
{
    _model = model;
    
    self.icon.frame = model.timeImageFrame;
    self.timeLbl.frame = model.timeFrame;
    self.timeLbl.text = model.formateTime;
    self.bgView.frame = model.contentViewFrame;
    
    self.titleLbl.attributedText = model.attr24Title;
    self.titleLbl.frame = model.attr24TitleFrame;
    
    
    if (model.isToday) {
        self.lineLayer.strokeColor = [UIColor blackColor].CGColor;
        self.timeLbl.textColor = [UIColor blackColor];
        //时间图片替换
        self.icon.image = [UIImage imageNamed:@"zdzx-clock"];
    }else{
        self.lineLayer.strokeColor = [UIColor colorWithHexString:battleshipGrey].CGColor;
        self.timeLbl.textColor = [UIColor colorWithHexString:battleshipGrey];
        //时间图片替换
        self.icon.image = [UIImage imageNamed:@"zx-unclock"];
        
    }
    
    //绘制虚线
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:model.dashStartPoint];
    [path addLineToPoint:model.dashEndPoint];
    self.lineLayer.path = path.CGPath;
    
}
+ (instancetype)cellWithTbaleview:(UITableView *)tableview
{
    static NSString *const dayNewsCell = @"YDADayNewsCell";
    
    YDADayNewsCell *cell = [tableview dequeueReusableCellWithIdentifier:dayNewsCell];
    if (cell == nil) {
        cell = [[YDADayNewsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:dayNewsCell];
        cell.backgroundColor = [UIColor colorWithHexString:mainGray];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self icon];
        [self timeLbl];
        [self bgView];
        [self titleLbl];
        [self postImage];
        [self lineLayer];
    }
    return self;
}

-(UIImageView *)icon
{
    if (_icon == nil) {
        _icon = [UIImageView new];
        [self.contentView addSubview:_icon];
        _icon.image = [UIImage imageNamed:@"zx-clock"];
        _icon.layer.cornerRadius = 5;
        _icon.layer.masksToBounds = YES;
        _icon.clipsToBounds = YES;
    }
    return _icon;
}

-(UILabel *)timeLbl
{
    if (_timeLbl == nil) {
        _timeLbl = [UILabel new];
        _timeLbl.text = @"12:39";
        _timeLbl.textColor = NumberColor(79, 187, 255);
        _titleLbl.backgroundColor = [UIColor colorWithHexString:mainGray];
        [self.contentView addSubview:_timeLbl];
        _timeLbl.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
        
    }
    return _timeLbl;
}
- (UIView *)bgView
{
    if (_bgView == nil) {
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.cornerRadius = 4;
        _bgView.clipsToBounds = YES;
        _bgView.layer.masksToBounds = YES;
        _bgView.userInteractionEnabled = YES;
        [self.contentView addSubview:_bgView];
        
    }
    return _bgView;
}
-(UILabel *)titleLbl
{
    if (_titleLbl == nil) {
        _titleLbl = [UILabel new];
        _titleLbl.numberOfLines = 0;
        _titleLbl.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        _titleLbl.text = @"【锰矿价格上涨，预计1月底左右会有集中采购出现】据百川资讯，锰矿价格今日上涨1元/吨度，涨幅1.52%。昨日下午天津港锰矿价格一片涨声，主流…";
        _timeLbl.lineBreakMode = NSLineBreakByTruncatingTail;
        _timeLbl.textColor = [UIColor colorWithHexString:dark];
        [self.contentView addSubview:_titleLbl];
    }
    return _titleLbl;
}
-(UIImageView *)postImage
{
    if (_postImage == nil) {
        _postImage = [[UIImageView alloc] init];
        [self.contentView addSubview:_postImage];
    }
    return _postImage;
}
-(CAShapeLayer *)lineLayer
{
    if (_lineLayer == nil) {
        CAShapeLayer *lineLayer = [CAShapeLayer layer];
        lineLayer.lineWidth = 1.0f;
        lineLayer.strokeColor = [UIColor colorWithHexString:@"FFA16D"].CGColor;
        [lineLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:4],[NSNumber numberWithInt:2],nil]];
        [self.contentView.layer addSublayer:lineLayer];
        _lineLayer = lineLayer;
    }
    return _lineLayer;
}



@end
